<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text"><button>点击</button>
    <div></div>
    <script>
        // var str = "     xu   ying    ";
        // var str_2 = str.trim();
        // console.log(str);

        // console.log(str_2);
        var input = document.querySelector("input");
        var btn = document.querySelector('button');
        var div = document.querySelector("div");
        btn.onclick = function() {
            var str = input.value.trim();
            if (str === '') {
                alert("请输入内容");
            } else {
                div.innerHTML = str;
            }
        }
    </script>
</body>

</html>